package fifthDay;

public class LengthOfLongestSubstring {
    public static void main(String[] args) {
        System.out.println(lengthOfLongestSubstring("   "));
    }
    public static int lengthOfLongestSubstring(String s) {
        if (s.length() == 1) {
            return 1;
        } else if (s.length() == 0) {
            return 0;
        }
        int ans = Integer.MIN_VALUE;
        int[] cont = new int[128];
        int left = 0;
        for (int i = 0; i < s.length(); i++) {
            cont[s.charAt(i) - ' ']++;
            while (cont[s.charAt(i) - ' '] > 1){
                cont[s.charAt(left) - ' ']--;
                left++;
            }
            ans = Math.max(ans,i - left + 1);
        }
        ans = Math.max(ans,0);
        return ans;
    }
}
